//////////////////////////////////////////////////////////////////////////////////////////////
//	File			:	"Player.cpp"
//
//	Author			:	Mike Davis, Matt Stover, James Thornton, Keith Webster
//	
//	Project			:	TacWars
//
//	Last Modified	:	11/6/2013
//
//	Purpose			:	
//
//////////////////////////////////////////////////////////////////////////////////////////////
#include "Player.h"
#include "../MapSystem/BattleMap.h"
#include <cassert>

Player::Player()
{
	Iterating = false;
}
Player::~Player()
{
	assert(Iterating == false && "~Player - cannot be destroyed while iterating");
}
void Player::AddUnit(Entity* Unit, vector<Entity*> &whatVec)
{
	assert(Iterating == false && "Player::AddUnit - cant add while iterating");
	assert(Unit != nullptr && "Player::AddUnit - pointer cannot be null");

	whatVec.push_back(Unit);
	Unit->AddRef();
}
void Player::RemoveUnit(Entity* Unit, vector<Entity*> &whatVec)
{
	assert (Iterating == false && "Player::RemoveUnit - cant remove while iterating");
	assert(Unit != nullptr && "Player::RemoveUnit - pointer cannot be null");
	Unit->GetOccupyingTile()->OccupyingUnit = nullptr;
	for(unsigned int i = 0; i < whatVec.size(); i--)
	{	
			if(whatVec[i] == Unit)
			{
				Unit->Release();
				whatVec.erase(whatVec.begin() + i);
				return;
			}
		}
}
void Player::RemoveAllUnits(vector<Entity*> &whatVec)
{
	assert(Iterating == false && "Player::RemoveAllUnits - cannot remove while iterating");
	for(unsigned int i = 0; i < whatVec.size(); i--)
	{
		whatVec[i]->Release();
	}
}
void Player::UpdateAll(float fElapsedTime, vector<Entity*> &whatVec)
{
	assert(Iterating == false && "Player::UpdateAll - cannot update while iterating");
	Iterating = true;
	for(unsigned int i = 0; i < whatVec.size(); i++)
	{
		whatVec[i]->Update(fElapsedTime);
	}
	Iterating = false;
}
void Player::RenderAll(vector<Entity*> whatVec)
{
	assert(Iterating == false && "Player::RenderAll - cannot render while iterating");
	Iterating = true;
	for(unsigned int i = 0; i < whatVec.size(); i++)
	{
		whatVec[i]->Render();
	}
	Iterating = false;
}